﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using BUS;

namespace GUI
{
    public partial class frmSanPham : DevComponents.DotNetBar.Office2007Form
    {
        public frmSanPham()
        {
            InitializeComponent();
        }
        SANPHAM sanpham = new SANPHAM();
        public void HienThi()
        {
            sanpham.MaSP = Convert.ToInt32(dgvDSSP.SelectedRows[0].Cells[0].Value.ToString());
            sanpham.TenSP = dgvDSSP.SelectedRows[0].Cells[1].Value.ToString();
            sanpham.GiaSP = Convert.ToDecimal(dgvDSSP.SelectedRows[0].Cells[2].Value.ToString());

            txtMaSP.Text = sanpham.MaSP.ToString();
            txtTenSP.Text = sanpham.TenSP;
            txtGiaSP.Text = sanpham.GiaSP.ToString();

        }
        private void frmSanPham_Load(object sender, EventArgs e)
        {
            dgvDSSP.DataSource = SanPhamBUS.layDSSP();
            dgvDSSP.Columns[3].Visible = false;
            dgvDSSP.Columns[4].Visible = false;
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            sanpham.TenSP = txtTenSP.Text;
            sanpham.GiaSP = Convert.ToDecimal(txtGiaSP.Text);

            SanPhamBUS.CapNhatSanPham(sanpham);
            dgvDSSP.DataSource = SanPhamBUS.layDSSP();

            txtMaSP.Text = null;
            txtTenSP.Text = null;
            txtGiaSP.Text = null;
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            sanpham.TenSP = txtTenSP.Text;
            sanpham.GiaSP = Convert.ToDecimal(txtGiaSP.Text);

            SanPhamBUS.ThemSanPham(sanpham);
            SanPhamBUS.layDSSP();
            dgvDSSP.DataSource = SanPhamBUS.layDSSP();

            txtMaSP.Text = null;
            txtTenSP.Text = null;
            txtGiaSP.Text = null;
        }

        private void dgvDSVe_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            HienThi();
        }

        private void dgvDSVe_KeyDown(object sender, KeyEventArgs e)
        {
            HienThi(); 
        }

        private void dgvDSVe_KeyUp(object sender, KeyEventArgs e)
        {
            HienThi();
        }
    }
}
